package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AttributeTemplateDTO;
import cn.tedu.csmall.product.pojo.dto.AttributeTemplateUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AttributeTemplateListItemVO;
import cn.tedu.csmall.product.pojo.vo.AttributeTemplateStandardVO;
import cn.tedu.csmall.product.service.impl.AttributeTemplateServiceImpl;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: AttributeTemplateController
 * Package: cn.tedu.csmall.product.controller
 * Description
 *
 * @version 0.0.1
 * @Author: 大傻
 * @Create:2022/12/3
 */
@RestController
@RequestMapping("/attributeTemplates")
@Api(tags = "04. 属性模板管理模块")
@Validated
@Slf4j
public class AttributeTemplateController {
    @Autowired
    AttributeTemplateServiceImpl attributeTemplateService;
    //http://localhost:9080/attributeTemplates/add-new
    @ApiOperation("添加模板")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated AttributeTemplateDTO attributeTemplateDTO){
        attributeTemplateService.addNew(attributeTemplateDTO);
        return JsonResult.ok();
    }

    //http://localhost:9080/attributeTemplates/1998/delete
    @ApiOperation("删除属性模板")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "属性模板ID", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理根据id删除模板请求,参数{}",id);
        attributeTemplateService.delete(id);
        return JsonResult.ok();
    }
    //http://localhost:9080/attributeTemplates/1998/update
    @ApiOperation("修改属性模板")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "属性模板ID", required = true, dataType = "long" )
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateInfoById(@PathVariable Long id, @Validated AttributeTemplateUpdateDTO attributeTemplateUpdateDTO){
        log.debug("开始处理根据id修改属性模板,参数{}",id);
        attributeTemplateService.update(id, attributeTemplateUpdateDTO);
        return JsonResult.ok();
    }


    //http://localhost:9080/albums/1998
    @ApiOperation("根据id查询属性模板")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "属性模板ID", required = true, dataType = "long" )
    @GetMapping("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id){
        log.debug("开始处理根据id查询相册详情的请求,参数:{}",id);
        AttributeTemplateStandardVO standardById = attributeTemplateService.getStandardById(id);
        return JsonResult.ok(standardById);
    }

    //http://localhost:9080/attributeTemplates/
    @ApiOperation("查询模板列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        List<AttributeTemplateListItemVO> list = attributeTemplateService.list();
        return JsonResult.ok(list);
    }


}
